#include "SingleWordRanker.h"
#include "../WellSizedVector2.h"
#include "../PositionVector.h"
#include <vector>
#include <iostream>
#include <math.h>

using namespace std;

SingleWordRanker::SingleWordRanker(uint w)
:weight(w)
{
}

SingleWordRanker::~SingleWordRanker()
{
}

vector<uint> SingleWordRanker::getRank(WellSizedVector2 myVector) {
	uint numDocs = myVector.getVectorSize();
	vector<uint> rankings(numDocs);
	for (uint i = 0; i < numDocs; i++) {
		PositionVector * posVec = myVector.getSpecificPositionVector(i);
		uint numPositions = posVec->getNumElements();
		uint lastPosition = posVec->getFirstOccurrence();
		for (uint j = 0; j < numPositions-1; j++) {
			uint offset = posVec->getOffsetAt(j);
			if (offset != -1)
				lastPosition += offset;
			else
				cout << "MC causou erro no SingleWordRanker..." << endl;
		}
		rankings[i] = uint(weight * numPositions / (lastPosition>50?lastPosition:50) );
	}
	return rankings;
}
